package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.EmployeeService;
import com.sky.service.impl.EmployeeServiceImpl;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/employee")
@Api(tags = "员工相关接口")
@Slf4j
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;
    /**
     * 管理端登录功能
     */
    @PostMapping("/login")
    @ApiOperation("登录功能")
    public Result Login(@RequestBody EmployeeLoginDTO employeeLoginDTO){
        log.info("管理员登录账户密码{}", employeeLoginDTO);
        EmployeeLoginVO employeeLoginVO = employeeService.checkLogin(employeeLoginDTO);
        return Result.success(employeeLoginVO);

    }
    /**
     * 新增员工功能
     */
    @PostMapping
    @ApiOperation("新增员工功能")
    public Result addEmp(@RequestBody  EmployeeDTO employeeDTO){
        log.info("前段传来的参数{}",employeeDTO );
        employeeService.addEmp(employeeDTO);
        return Result.success();
    }

    /**
     * 员工分页查询功能
     */
    @GetMapping("/page")
    @ApiOperation("分页查询功能")
    public Result<PageBean> page(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工分页查询功能{}",employeePageQueryDTO );
        PageBean pageBean= employeeService.pageQuery(employeePageQueryDTO);
        return Result.success(pageBean);
    }
    /**
     * 员工状态设置
     */
    @PostMapping("/status/{status}")
    @ApiOperation("员工状态更新")
    public Result  setStatus(@PathVariable Integer status,Long id){
        log.info("员工更新状态{}，{}", status,id);
        employeeService.setStatus(status,id);
        return Result.success();
    }
    /**
     * 根据id查找员工
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查找员工")
    public Result<Employee> getById(@PathVariable  Integer id){
        log.info("根据id查找员工{}", id);
        Employee employee= employeeService.getById(id);
        return Result.success(employee);
    }

    /**
     * 更新员工
     */
    @PutMapping
    @ApiOperation("更新员工信息")
    public Result  updateById(@RequestBody EmployeeDTO employeeDTO){
        log.info("更新员工信息{}",employeeDTO);
        employeeService.updateById(employeeDTO);
        return Result.success();
    }



}
